package com.traffic.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.utils.BaseUtil;
import com.traffic.domain.FamilyAbroad;
import com.traffic.service.IFamilyAbroadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 亲属出国信息Controller
 * 
 * @author zzs
 * @date 2024-11-11
 */
@RestController
@RequestMapping("/abroad")
public class FamilyAbroadController extends BaseController
{
    @Autowired
    private IFamilyAbroadService familyAbroadService;

    /**
     * 查询亲属出国信息列表
     */
    @RequiresPermissions("information:abroad:list")
    @GetMapping("/list")
    public TableDataInfo list(FamilyAbroad familyAbroad)
    {
        Long curId= BaseUtil.getCurrentId();
        familyAbroad.setUserId(curId);
        startPage();
        List<FamilyAbroad> list = familyAbroadService.selectFamilyAbroadList(familyAbroad);
        return getDataTable(list);
    }

    /**
     * 导出亲属出国信息列表
     */
    @RequiresPermissions("information:abroad:export")
    @Log(title = "亲属出国信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FamilyAbroad familyAbroad)
    {
        List<FamilyAbroad> list = familyAbroadService.selectFamilyAbroadList(familyAbroad);
        ExcelUtil<FamilyAbroad> util = new ExcelUtil<FamilyAbroad>(FamilyAbroad.class);
        util.exportExcel(response, list, "亲属出国信息数据");
    }

    /**
     * 获取亲属出国信息详细信息
     */
    @RequiresPermissions("information:abroad:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(familyAbroadService.selectFamilyAbroadById(id));
    }

    /**
     * 新增亲属出国信息
     */
    @RequiresPermissions("information:abroad:add")
    @Log(title = "亲属出国信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FamilyAbroad familyAbroad)
    {
        Long curId= BaseUtil.getCurrentId();
        familyAbroad.setUserId(curId);
        return toAjax(familyAbroadService.insertFamilyAbroad(familyAbroad));
    }

    /**
     * 修改亲属出国信息
     */
    @RequiresPermissions("information:abroad:edit")
    @Log(title = "亲属出国信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FamilyAbroad familyAbroad)
    {
        return toAjax(familyAbroadService.updateFamilyAbroad(familyAbroad));
    }

    /**
     * 删除亲属出国信息
     */
    @RequiresPermissions("information:abroad:remove")
    @Log(title = "亲属出国信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(familyAbroadService.deleteFamilyAbroadByIds(ids));
    }
}
